<template>
  账号：<input type="text" v-model="username"><br />
  密码：<input type="password" v-model="password" /><br />
  <button @click="handleLogin">登录</button>

  <button @click="handleUserinfo">获取用户信息</button>
</template>

<script>
import requestUtil from '@/util/request'
import store from '@/store'

export default {
  data(){
    return {
      username : '',
      password : ''
    }
  },
  methods: {
    async handleLogin(){
      let res = await requestUtil.post('api/user/login')
      let data = res.data
      if (data.status == 1) {
        const token = data.message
        console.log(token)
        store.commit('SET_TOKEN', token)
      } else {
        console.log('登录失败')
      }
    },

    async handleUserinfo(){
      let res = await requestUtil.get('api/user/find')
      let data = res.data
      if (data.status == 1) {
        console.log(data.data)
      } else {
        console.log(data.message)
      }
    }
  }

}

</script>

<style>

</style>
